home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / dir / dir.gc < prev    next >
Text File  |  1999-04-29  |  8KB  |  388 lines

  1. G4C
  2.  
  3. ; This is a Full blown File Manager.
  4.  
  5. ; I know it's difficult to follow specially since it consists
  6. ; of many GUIs which open-close on their own, but.. hey, it's
  7. ; a tough world out there..
  8.  
  9. ; The main variable used is "lv_file", which is the name of the
  10. ; variable where both listviews will store the files selected.
  11.  
  12. ; Get the full archive of Gui4Cli (Aminet:Dev/Gui/Gui4Cli.lha),
  13. ; read the guide and construct the file manager of your dreams! 
  14.  
  15.  
  16. WINBIG 150 11 220 229 Devices
  17. WinType 11110001
  18. varpath ''
  19. nofontsense
  20.  
  21. xOnLoad
  22.     fm_mode = 1
  23.     setgad Dir.gc 2       HIDE       ; hide the gadgets of the
  24.     setgad Dir.gc 201/210 HIDE
  25.     setgad Dir.gc 10      HIDE
  26.     guiopen Dir.gc
  27.     guiload :Dir.g                     ; load the helper guis
  28.     guiload :dir.g2
  29.     guiload :dir.popfav
  30.     guiload guis:tools/Prefs/players   ; the default viewers
  31.     favmode.1 = 0
  32.     favmode.2 = 0
  33.  
  34. xonreload
  35.     guiopen dir.gc
  36.  
  37. xonquit
  38.     guiquit Dir.g        ; quit our other guis also
  39.     guiquit Dir.g2
  40.     guiquit Dir.g3
  41.     guiquit dir.g4
  42.     guiquit dir.pop2
  43.     guiquit cli.gc
  44.     guiquit dir.prot
  45.     guiquit dir.user
  46.     guiquit dir.popfav
  47.     guiquit getfiletype
  48.     guiquit viewfile    ; it will quit viewfile2
  49.  
  50. xOnOpen
  51.     SetGad dir.gc 20 OFF
  52.  
  53. xOnClose 
  54.     SetGad dir.gc 20 ON
  55.  
  56.  
  57. xAppIcon 0 0 :dir.gc DIR.gc *lv_app OFF
  58.     GadID 20
  59.     GuiOpen dir.gc
  60.     GuiScreen dir.gc FRONT
  61.     if $*lv_app > " "
  62.        gosub dir.gc appdir 
  63.     endif
  64.  
  65.  
  66. xAppWindow  *lv_app                ; The FM is also an AppWindow
  67.     gosub dir.gc appdir             ; going to the dir of the icon..
  68.  
  69.  
  70. xroutine appdir                    ; cd to the appitem's dir
  71.     ifexists DIR $*lv_app           ; if it's a dir,vol,dev or asn
  72.     orifexists DOS $*lv_app
  73.         dir  = $*lv_app
  74.         file = ''
  75.     elseifexists file $*lv_app      ; if it's a file
  76.         extract *lv_app PATH dir
  77.         extract *lv_app FILE file
  78.     endif
  79.     lvuse dir.gc 1
  80.     lvdir #$dir
  81.     lvfind $file
  82.     setwintitle dir.gc '$dir'
  83.     delvar *lv_app
  84.  
  85. xOnRMB
  86.     if $favmode.1 > 0
  87.        favid = 1
  88.        guiopen dir.popfav
  89.     elseif $favmode.2 > 0
  90.        favid = 2
  91.        guiopen dir.popfav
  92.     else
  93.        guiopen Dir.g     ; This has the copy, delete etc functions
  94.     endif
  95.  
  96.  
  97. ; ===================================================================
  98. ;     The directory listviews
  99. ; ===================================================================
  100.  
  101. ; Note they both have Hooks to display the current dir to the user.
  102.  
  103. ;---------> the left side
  104.  
  105. XLISTVIEW 0 0 204 228 "" lv_file "" 10 DIR
  106.     gadid 1
  107.     lvdirhook 1
  108.     GadFont #mono 8 000        ; CHANGE THIS TO THE FONT YOU LIKE!
  109.     ; LVColors   2 1 3 2    ; uncomment this line for genlocking
  110.     ; attr dirstyle 2031       ; uncomment for 3D dirs
  111.  
  112.     if $favmode.1 = 1
  113.        cutvar lv_file cut word -1 lv_file
  114.        extract lv_file clean lv_file
  115.        if $lv_file == TITLE
  116.           stop
  117.        endif
  118.        favmode.1  = 0
  119.        lvmode DIR
  120.        lvdir #$lv_file
  121.        setwintitle Dir.gc '$lv_file'
  122.     else
  123.        guiopen Dir.g2
  124.     endif
  125.  
  126. xLVDirHook 1
  127.     setwintitle Dir.gc '$$lv.dir'   ; show it in the wintitle
  128.  
  129. ;----------> the right side
  130.  
  131. XLISTVIEW 220 16 205 212 "" lv_file "" 10 DIR
  132.     gadid 2
  133.     lvdirhook 2
  134.     GadFont #mono 8 000        ; CHANGE THIS TO THE FONT YOU LIKE!
  135.     ; LVColors   2 1 3 2    ; uncomment this line for genlocking
  136.     if $favmode.2 = 1
  137.        cutvar lv_file cut word -1 lv_file
  138.        extract lv_file clean lv_file
  139.        if $lv_file == TITLE
  140.           stop
  141.        endif
  142.        favmode.2  = 0
  143.        lvmode DIR
  144.        lvdir #$lv_file
  145.        update Dir.gc 10 $lv_file
  146.     else
  147.        guiopen Dir.g2
  148.     endif
  149.  
  150. xLVDirHook 2
  151.     update Dir.gc 10 $$lv.dir       ; show it in xTextIn gadget below
  152.  
  153. XTEXTIN 220 0 204 16 "" lvdir2 "" 140
  154.     gadid 10
  155.     GadFont topaz.font 8 000
  156.     lvuse dir.gc 2
  157.     LVDir #$lvdir2   ; you can change the dir from here
  158.  
  159. ; ===================================================================
  160. ;     Disk in/out events
  161. ; ===================================================================
  162.  
  163. xondiskin
  164.     gosub dir.gc diskrefresh
  165.  
  166. xondiskout
  167.     gosub dir.gc diskrefresh
  168.  
  169. xroutine diskrefresh
  170.     lvuse dir.gc 1
  171.     if $$lv.dir = ''     ; refresh if it's a device list
  172.        lvdir disks
  173.     endif
  174.     lvuse dir.gc 2
  175.     if $$lv.dir = ''
  176.        lvdir disks
  177.     endif
  178.  
  179. ; ===================================================================
  180. ;     Listview control buttons
  181. ; ===================================================================
  182.  
  183. ;--------> for the left side (source)
  184.  
  185. XBUTTON 205 0 14 13 P
  186.     GadID 101
  187.     lvuse dir.gc 1
  188.     LVDir parent
  189.     lv_dir1 = $$LV_DIR
  190.     setwintitle Dir.gc '$$lv.dir'
  191.  
  192. XBUTTON 205 13 14 13 R
  193.     GadID 102
  194.     lvuse dir.gc 1
  195.     LVDir Root
  196.     lv_dir1 = $$LV_DIR
  197.     setwintitle Dir.gc '$$lv.dir'
  198.  
  199. XBUTTON 205 26 14 13 D
  200.     GadID 103
  201.     lvuse dir.gc 1
  202.     LVDir Disks
  203.     lv_dir1 = ""
  204.     setwintitle Dir.gc 'Devices'
  205.  
  206. XBUTTON 205 39 14 13 A
  207.     GadID 104
  208.     lvuse dir.gc 1
  209.     LVDir all
  210.  
  211. XBUTTON 205 52 14 13 N
  212.     GadID 105
  213.     lvuse dir.gc 1
  214.     LVDir None
  215.  
  216. XBUTTON 205 65 14 15 F
  217.     GadID 106
  218.     lvuse dir.gc 1
  219.     lvmode MULTI
  220.     lvchange guis:tools/fav/DirDef
  221.     favmode.1 = 1
  222.     favid = 1
  223.  
  224. XBUTTON 205 177 14 12 +      ; add to favourites
  225.     GadID 107
  226.     lvuse dir.gc 1
  227.     gosub dir.gc addfav
  228.  
  229. XBUTTON 205 189 14 13 R
  230.     GadID 108
  231.     lvuse dir.gc 1
  232.     lvdir Refresh
  233.  
  234. XBUTTON 205 202 14 13 <       ; move list left
  235.     GadID 109
  236.     lvuse dir.gc 1
  237.     lvmove -10
  238.  
  239. XBUTTON 205 215 14 13 >
  240.     GadID 110
  241.     lvuse dir.gc 1
  242.     lvmove 10
  243.  
  244. ;---------> for the right side (destination) give gadID so we set them on/off
  245.  
  246. XBUTTON 426 0 14 13 P
  247.     GadID 201
  248.     lvuse dir.gc 2
  249.     LVDir parent
  250.     setvar lv_dir2 $$LV.DIR
  251.     update Dir.gc 10 $$lv.dir
  252.  
  253. XBUTTON 426 13 14 13 R
  254.     gadid 202
  255.     lvuse dir.gc 2
  256.     LVDir Root
  257.     setvar lv_dir2 $$LV.DIR
  258.     update Dir.gc 10 $$lv.dir
  259.  
  260. XBUTTON 426 26 14 13 D
  261.     gadid 203
  262.     lvuse dir.gc 2
  263.     LVDir Disks
  264.     setvar lv_dir2 ""
  265.     update Dir.gc 10 ""
  266.  
  267. XBUTTON 426 39 14 13 A
  268.     gadid 204
  269.     lvuse dir.gc 2
  270.     LVDir All
  271.  
  272. XBUTTON 426 52 14 13 N
  273.     gadid 205
  274.     lvuse dir.gc 2
  275.     LVDir None
  276.  
  277. XBUTTON 426 65 14 15 F
  278.     gadid 206
  279.     lvuse dir.gc 2
  280.     lvmode MULTI
  281.     lvchange guis:tools/fav/DirDef
  282.     favmode.2 = 1
  283.     favid = 2
  284.  
  285. XBUTTON 426 178 14 11 +      ; add to favourites
  286.     gadid 207
  287.     lvuse dir.gc 2
  288.     gosub dir.gc addfav
  289.  
  290. XBUTTON 426 189 14 13 R
  291.     gadid 208
  292.     lvuse dir.gc 2
  293.     lvdir Refresh
  294.  
  295. XBUTTON 426 202 14 13 <    ; move list left
  296.     GadID 209
  297.     lvuse dir.gc 2
  298.     lvmove -10
  299.  
  300. XBUTTON 426 215 14 13 >    ; move list right
  301.     GadID 210
  302.     lvuse dir.gc 2
  303.     lvmove 10
  304.  
  305. ;---------> open full file manager
  306.  
  307. XBUTTON 205 108 14 11 >
  308.     gadid 11
  309.     if $fm_mode = 1
  310.        gosub Dir.gc OpenWindow
  311.     else
  312.        gosub Dir.gc CloseWindow
  313.     endif
  314.  
  315.  
  316. ;--------> button to switch left <-> right lvs
  317.  
  318. XBUTTON 205 119 14 11 x
  319.     gadid 12
  320.     lvuse dir.gc 1
  321.     tempdir1 = $$lv.dir
  322.     lvuse dir.gc 2
  323.     tempdir2 = $$lv.dir
  324.     lvdir #$tempdir1
  325.     lvuse dir.gc 1
  326.     lvdir #$tempdir2
  327.     setwintitle Dir.gc '$tempdir2' ; and their dir displays
  328.     update Dir.gc 10 $tempdir1
  329.     delvar tempdir#?
  330.  
  331.  
  332. ;--------> same directories
  333.  
  334. XBUTTON 205 130 14 11 =
  335.     gadid 13
  336.     if $$lv.gui == dir.gc        ; check that the internal vars point to us
  337.        id  = $$lv.id
  338.        dir = $$lv.dir
  339.        if $id = 1
  340.           lvuse dir.gc 2 
  341.           lvdir #$dir
  342.           update Dir.gc 10 $dir
  343.        else
  344.           lvuse dir.gc 1
  345.           lvdir #$dir
  346.           setwintitle Dir.gc '$dir'
  347.        endif
  348.     endif
  349.  
  350. ;---------> ROUTINES
  351.  
  352. xRoutine OpenWindow     ; Routine to enlarge the window
  353.    fm_mode = 2
  354.    setgad Dir.gc 2       SHOW
  355.    setgad Dir.gc 201/210 SHOW
  356.    setgad Dir.gc 10      SHOW
  357.    changearg Dir.gc 11 4 <
  358.    changegad Dir.gc 0 -1 -1 440 229 ""
  359.    redraw Dir.gc
  360.  
  361. xRoutine CloseWindow    ; make it small again
  362.    fm_mode = 1
  363.    setgad Dir.gc 2       HIDE
  364.    setgad Dir.gc 201/210 HIDE
  365.    setgad Dir.gc 10      HIDE
  366.    changegad Dir.gc 0 -1 -1 220 229 ""
  367.    changearg Dir.gc 11 4 >
  368.    redraw Dir.gc
  369.  
  370. xroutine addfav         ; add a path to the favourites
  371.     ; see first if path exists
  372.     favdir = $$lv.dir
  373.     cli 'guis:c/fsearch >env:.addfav guis:tools/fav/DirDef txt=$favdir'
  374.     if $.addfav > " "
  375.        ; path already exists
  376.     else
  377.        ; get dir name as identifier name
  378.        extract favdir file favname
  379.        ; append entry to the favourites file
  380.        append guis:tools/fav/DirDef '\n$favname\t\t\t\t$favdir'
  381.     endif
  382.     delvar .addfav
  383.  
  384.  
  385.  
  386.  
  387. RESIZE_BIG 114 11 267 250 DIR.GC
  388.